#include <iostream>
#include <math.h>
using namespace std;
const int inf=0x7fffffff;


int check(int mid,int n,int *a){
	int sum=1;
	int num=0;
	for(int i=0;i<n;i++){
		if((num += a[i]) > mid){
			num = a[i];
			sum++;
		}
	}
	return sum;
}


int main(){
	int n,m;
	cin>>n>>m;
	int a[n];
	int l=inf+1,r=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		l = max(l,a[i]);
		r += a[i];
	}
	
	while(r-l > 1){
		int mid=(l+r)/2;
//		cout<<l<<" "<<mid<<" "<<r<<endl;
		if(check(mid,n,a) <= m)
			r = mid;
		else
			l = mid;
	}
//	cout<<check(l,n,a)<<" "<<l<<" "<<r<<endl;
	cout<<((check(l,n,a)<=m)?l:r);
	return 0;
}
